#!/bin/bash


shdir=$(pwd)/FYT2023.sh
shdir1=$(pwd)/openroscore.sh
shdir2=$(pwd)/openconfig.sh
shdir3=$(pwd)/openimg_catcher.sh
shdir4=$(pwd)/opentest_img_catcher.sh

shdir_tls=$(pwd)

echo "#!/bin/bash" > $shdir1
echo "cd ../" >> $shdir1
echo "source devel/setup.bash" >> $shdir1
echo "roscore" >> $shdir1

echo "#!/bin/bash" > $shdir2
echo "cd ../" >> $shdir2
echo "source devel/setup.bash" >> $shdir2
echo "rosrun config node" >> $shdir2

echo "#!/bin/bash" > $shdir3
echo "cd ../" >> $shdir3
echo "source devel/setup.bash" >> $shdir3
echo "rosrun img_catcher node" >> $shdir3

echo "#!/bin/bash" > $shdir4
echo "cd ../" >> $shdir4
echo "source devel/setup.bash" >> $shdir4
echo "rosrun test_img_catcher node" >> $shdir4

echo "#!/bin/bash" > $shdir
#echo "cd ../" >> $shdir
#echo "catkin_make --pkg fyt_msg" >> $shdir
#echo "catkin_make" >> $shdir
#echo "sleep 8s" >> $shdir
#echo "cd Tools" >> $shdir
echo '{' >> $shdir
echo "   gnome-terminal -- bash -c ""$shdir_tls/openroscore.sh;exec bash""" >> $shdir
echo '}&' >> $shdir
echo 'sleep 1s' >> $shdir
echo '{' >> $shdir
echo "   gnome-terminal -- bash -c ""$shdir_tls/openconfig.sh;exec bash""" >> $shdir
echo '}&' >> $shdir
echo 'sleep 1s' >> $shdir
echo '{' >> $shdir
echo "   gnome-terminal -- bash -c ""$shdir_tls/openimg_catcher.sh;exec bash""" >> $shdir
echo '}&' >> $shdir
echo 'sleep 1s' >> $shdir 
echo '{' >> $shdir
echo "   gnome-terminal -- bash -c ""$shdir_tls/opentest_img_catcher.sh;exec bash""" >> $shdir 
echo '}' >> $shdir
echo "cd $(pwd)" >> $shdir
echo "$(pwd)/FYT2023" >> $shdir


sudo chmod +x $(pwd)/openroscore.sh
sudo chmod +x $(pwd)/openconfig.sh
sudo chmod +x $(pwd)/openimg_catcher.sh
sudo chmod +x $(pwd)/opentest_img_catcher.sh

sudo cp ./FYT2023.service /etc/systemd/system/ #将服务文件FYT2021.service加入到系统服务文件夹中
sudo cp $shdir /bin/ #将FYT2021.sh复制到 /bin 文件夹中
sudo chmod +x /bin/FYT2023.sh #给bin中的FYT2021.sh赋予可执行权限
sudo chmod +x $(pwd)/FYT2023.sh #给bin中的FYT2021.sh赋予可执行权限
sudo systemctl daemon-reload #刷新系统服务列表
sudo systemctl enable FYT2023.service #启动系统服务
